package com.hhxy.practice;

import java.util.Random;
import java.util.Scanner;

//判断双色球是否中奖
public class UnionLotto {
    public static void main(String[] args) {
        int[] lunckNumber = new int[7];
        generateLuckNumber(lunckNumber);
//        System.out.println("双色球的幸运号码为：");
//        for (int i = 0; i < lunckNumber.length; i++) {
//            System.out.println(lunckNumber[i]);
//        }
        int[] inputNumber = userInputNumber();
/*        System.out.println("用户输入的双色球号码为：");
        for (int i = 0; i < inputNumber.length; i++) {
            System.out.println(inputNumber[i]);
        }*/
        switch (judge(lunckNumber, inputNumber)) {
            case 0:
                System.out.println("对不起你没有中奖");
                break;
            case 1:
                System.out.println("恭喜您中了一等奖，奖金为1000万元");
                break;
            case 2:
                System.out.println("恭喜您中了二等奖，奖金为500万元");
                break;
            case 3:
                System.out.println("恭喜您中了三等奖，奖金为3000元");
                break;
            case 4:
                System.out.println("恭喜您中了四等奖，奖金为200元");
                break;
            case 5:
                System.out.println("恭喜您中了五等奖，奖金为10元");
                break;
            case 6:
                System.out.println("恭喜您中了六等奖，奖金为5元");
                break;
        }
    }

    //随机生成幸运号码
    private static void generateLuckNumber(int[] lunckNumber) {
        Random r = new Random();
        int redNumber;
        int i = 0;
        while (i < lunckNumber.length - 1) {//对6个红球进行随机不重复的选号
            redNumber = r.nextInt(33) + 1;//红球号码的范围：1~33
            boolean f = true;//用于判断是否重复
            for (int j = 0; j < i; j++) {//红球去重
                if (redNumber == lunckNumber[j]) {
                    f = false;
                    break;
                }
            }
            if (f) {
                lunckNumber[i] = redNumber;
                i++;
            }
        }
        lunckNumber[6] = r.nextInt(16) + 1;//蓝球号码的范围：1~16
    }


    //用户输入号码
    private static int[] userInputNumber() {
        Scanner sc = new Scanner(System.in);
        int[] inputNumber = new int[7];
        System.out.println("请输入7个不同的双色球号码：");
        for (int i = 0; i < inputNumber.length; i++) {
            System.out.println("请输入第" + (i + 1) + "个球的号码");
            inputNumber[i] = sc.nextInt();
        }
        return inputNumber;
    }

    //判断中奖情况
    private static int judge(int[] lunckNumber, int[] inputNumber) {
        int countBlue = 0;
        int countRed = 0;
        if(lunckNumber[6]==inputNumber[6]){
            countBlue = 1;
        }
        for(int i=0;i<6;i++){
            for(int j=0;j<6;j++){
                if(lunckNumber[i]==inputNumber[j]){
                    countRed++;
                }
            }
        }
        if((countBlue==1 && countRed==6)){
            return 1;
        }else if(countBlue==0 && countRed==6){
            return 2;
        }else if(countBlue==1 && countRed==5){
            return 3;
        }else if(countBlue==0 && countRed==5){
            return 4;
        }else if((countRed==4 && (countBlue==0 || countBlue==1)) || (countRed==3 &&countBlue==1)){
            return 5;
        }else if(countBlue==1 && (countRed==0 || countRed==1 || countRed==2)){
            return 6;
        }
        return 0;
    }
}
